<template>
  <div style="min-height: 500px">
    <el-tree ref="rolepermissiontree" :data="treeData" node-key="id"
             show-checkbox check-strictly default-expand-all  highlight-current>
    </el-tree>

    <div class="mt_5 tac">
      <el-button type="primary" size="mini" @click="saveRolePermission">确定</el-button>
    </div>
  </div>
</template>

<script>
import request from '@/utils/request'

export default {
  props:['roleId'],
  data() {
    return {
      treeData : [],
    }
  },
  mounted() {
    this.loadRolePermissionTreeData();
  },
  methods: {
    loadRolePermissionTreeData(){
      request({
        url: '/sys/role/getrolepermission',
        data: {roleId:this.roleId}
      }).then( (res) => {
        this.treeData = res.data.permissionAllNode
        this.$nextTick(()=>{
          this.$refs.rolepermissiontree.setCheckedKeys(res.data.checkedIds)
        })
      })
    },
    saveRolePermission(){
      let rolePermissions = this.$refs.rolepermissiontree.getCheckedKeys();
      request({
        url: '/sys/role/saverolepermission',
        data: {roleId : this.roleId, rolePermissions:rolePermissions}
      }).then(res=>{
        if(res.code === '200'){
          this.$message.success(res.msg)
        }
      })
    },
  }
}
</script>

<style scoped>

</style>
